package com.koron.ui;

import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;

import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.text.JTextComponent;

public abstract class ChangeAction {
	@SuppressWarnings("rawtypes")
	public void addComponent(JComponent... components) {
		for (JComponent c : components) {
			if (c instanceof JTextComponent) {
				((JTextComponent) c).getDocument().addDocumentListener(new DocumentListener() {
					@Override
					public void removeUpdate(DocumentEvent e) {
						action();
					}

					@Override
					public void insertUpdate(DocumentEvent e) {
						action();
					}

					@Override
					public void changedUpdate(DocumentEvent e) {
						action();
					}
				});
			} else if (c instanceof JComboBox)
				((JComboBox) c).addItemListener(new ItemListener() {
					public void itemStateChanged(ItemEvent e) {
						action();
					}
				});
		}
	}

	public abstract void action();
}
